package map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
/**
 * Key计算hash决定数组位置
 * 同一位置value比较，不同add，相同replace（顺序的第一个）
* @ClassName: HashMapTest
* @Description: TODO(原理：https://blog.csdn.net/visant/article/details/80045154)
* @author hsj
* @email 2356899074@qq.com
* @date 2019年6月5日
*
 */
public class HashMapTest {
  public static void main(String[] args) {
	  Map<Object,Object> map = new HashMap<Object,Object>();
	  map.put(null, "HSJ");
	  map.put("hsj", "HSJ");
	  map.put("hsj", "HSJ");
	  map.put(new HSJ(), "HSJ");
	  map.put(new HSJ(), "HSJ");
	  map.put(new HSJ(), "HSJ");
	  map.put(new LBY(), "LBY");
	  map.put(new LBY(), "LBY");
	  Iterator<Entry<Object, Object>> i = map.entrySet().iterator();
	  while (i.hasNext()) {
		  Entry<Object, Object> e = i.next();
		  System.out.println("key="+e.getKey()+",value="+e.getValue());
	  }
//	  System.out.println("hsj".hashCode());
//	  System.out.println("hsj".hashCode());
//	  System.out.println("hsj".hashCode());
//	  System.out.println("hsj0".hashCode());
//	  System.out.println("hsj0".hashCode());

  }
}

class HSJ{

	@Override
	public int hashCode() {
		return 10;
	}

	@Override
	public boolean equals(Object obj) {
		return false;
	}
	
}

class LBY{

	/*@Override
	public int hashCode() {
		return 10;
	}*/

	@Override
	public boolean equals(Object obj) {
		return true;
	}
	
}
